import isMobile from 'is-mobile'

export default function ({ req, redirect, route }) {
  const mobile = isMobile({ ua: req })
  const fullpath = route.fullPath
  console.log(fullpath)
  if (fullpath === '/') return redirect('/pc/home') // 重定向到首页
  if (
    (mobile && fullpath.includes('/mobile/')) ||
    (!mobile && fullpath.includes('/pc/'))
  )
    return
  const replaceStr = mobile ? '/mobile' : '/pc'
  const redirectPath = fullpath.replace(/^\/\w+/, replaceStr)
  return redirect(redirectPath)
}
